<?php

use yii\helpers\Html;
use common\components\helpers\Fun;
use common\components\extenders\MenuManage;
use doumiaoduo\layer\LayerAsset;

?>
    <div class="docs-main">
        <table id="tablesaw" class="tablesaw table yx-table1 yx-table3 table-striped with-check">
            <thead>
            <tr class="yx-bgd2f6ec">
                <td>课程名称</td>
                <td>学员</td>
                <td>上课日期</td>
                <td>上课时间</td>
                <td>课次</td>
                <td>状态</td>
                <td>操作</td>
            </tr>
            </thead>
            <?php foreach ($details as $i => $v): ?>
                <tr>
                    <td><?= \yii\helpers\Html::encode($v['title']) ?></td>
                    <td><?= \yii\helpers\Html::encode($v['name']) ?></td>
                    <td><?= $v['class_date'] ?></td>
                    <td><?= $v['time'] ?></td>
                    <td><?= \yii\helpers\Html::encode($v['lesson']) ?></td>
                    <td><?php
                        $nowDate = date('Y-m-d', time());

                        if ($v['status'] == 0 && $nowDate > $v['class_date']) {
                            echo '旷课';
                        } elseif ($v['status'] == 2) {
                            echo '请假';
                        } elseif ($v['status'] == 3) {
                            echo '退课';
                        } elseif ($v['status'] == 1) {
                            echo '已打卡';
                        } elseif ($v['status'] == 4) {
                            echo '已转班';
                        } elseif ($v['status'] == 5) {
                            echo '老师请假';
                        } elseif ($v['status'] == 6) {
                            echo '停课';
                        } elseif ($v['status'] == 7) {
                            echo '已调课';
                        } else {
                            echo '未打卡';
                        }
                        ?></td>
                    <td style="overflow: hidden">
                        <?php
                        if ($v['status'] == 0 && $nowDate >= $v['class_date']) {
                            ?>
                            <?= (new MenuManage(MenuManage::TOP_MENU))->detailsMenu('newclassmanage', 'signin', false, ['class' => 'signin btn yx-radius2 yx-d-card yx-bg94d5a2 yx-radius2','style'=>'line-height:18px;', 'data' => ['id' => $v['id'], 'val' => $v['id']]]); ?>
                        <?php } else {
                            ?>
                            <button class="yx-btn-disabled" style="width:62px;line-height: 20px;" type="button">打卡</button>
                        <?php }; ?>
                        <?php if ($v['status'] == 0 && $nowDate >= $v['class_date']) { ?>
                            <?= (new MenuManage(MenuManage::TOP_MENU))->detailsMenu('newclassmanage', 'leave', true, ['class' => 'btn yx-radius2 yx-d-card yx-bg94d5a2 yx-radius2','style'=>'line-height:18px;','data' => ['id' => $v['id']]]); ?>
                        <?php } else { ?>
                            <?php if ($v['status'] == 2) { ?>
                                <?= (new MenuManage(MenuManage::TOP_MENU))->detailsMenu('newclassmanage', 'lookleave', true, ['class' => 'btn yx-radius2 yx-d-card yx-bg94d5a2 yx-radius2','style'=>'line-height:18px;', 'data' => ['id' => $v['id']]]); ?>
                            <?php } else { ?>
                                <button class="yx-btn-disabled" style="width:50px;line-height: 20px;" type="button">请假</button>
                            <?php } ?>

                        <?php } ?>
                    </td>
                </tr>
            <?php endforeach; ?>
        </table>
        <?php ?>
        <?php if ($model->is_frequency == 0) { ?>
            <div><?= (new MenuManage(MenuManage::TOP_MENU))->detailsMenu('newclassmanage', 'unlimitedsign', true, ['class' => 'btn yx-radius2 yx-d-card yx-bg94d5a2 yx-radius2','style'=>'line-height:18px;', 'data' => ['id' => $model->id]]); ?></div>
        <?php } ?>
        <div id="return" style="position: absolute;z-index: -1000; left: 10px; top: 10px;"></div>
    </div>

<?php
LayerAsset::register($this);
$js = <<<JS
    layer.config({
        extend: ['skin/customskin/style.css']//加载您的扩展样式
    });
    $(document).on('click','.signin',function(){
        var _this = $(this);
        var url = _this.data('url');
        var name = _this.parents('tr').find('td').eq(1).html();
        var day = _this.parents('tr').find('td').eq(2).html();
        var status = _this.parents('tr').find('td').eq(5);
        var val = _this.data('val');
         layer.confirm("确定给"+name+"打"+day+"的卡么？", {
            title: '打卡',
            area: ['440px', '270px'],
            skin: 'layui-confirm-customskin',
            shift:1,
            id:'layer-iframe',
            btn: ['确定','取消'],
            yes: function(index, layero){
                 $.ajax({
                    url:url,
                    type:'get',
                    dataType:'json',
                    _csrf:yii.getCsrfToken(),
                    success:function(data){
                        if(data.status == 1){
                            layer.msg("打卡成功！",{id:'layer-msg',skin: 'layui-msg-customskin',time: 1000});
                            $('#return').html(data.str);
                            _this.parent().html('');
                            status.html('已打卡');
                            $("#return").jqprint(); 
                            $("#return").html('');
                        }else if(data.status == 2){
                           layer.msg("请在上课当天打卡！",{id:'layer-msg',skin: 'layui-msg-customskin',time: 1000});
                            return false;
                        }else{
                            layer.msg("打卡失败！",{id:'layer-msg',skin: 'layui-msg-customskin',time: 1000});
                            return false;
                        }
                    }

                });
              layer.close(index);
            }
         });
        return false;
    });

JS;
\Yii::$app->view->registerJs($js);
?>